<template>
  <a-modal
    title="价格导入"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
    style="top: 20px"
  >

    <!-- 查询区域 -->
    <div>
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="48">

          <a-col>
            <a-form-item label="请选择渠道" style="margin-left: 250px;">
              <j-dict-select-tag v-model="queryParam.channelId" placeholder="请选择渠道" style="width: 180px;"
                                 dictCode="stm_channel_info,name,id,status!=0"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col>
            <div  style="margin-left: 250px; margin-top: 30px;">
              <a-upload
                name="file"
                :showUploadList="false"
                :multiple="false"
                :headers="tokenHeader"
                :data="{'channelId': queryParam.channelId}"
                :action="importExcelUrl" @change="handleImport">
                <a-button type="primary" icon="import" ref="import">导入价格</a-button>
              </a-upload>
            </div>

          </a-col>
        </a-row>

      </a-form>
    </div>
  </a-modal>
</template>

<script>
import pick from "lodash.pick";
import {downFile, httpAction} from "@/api/manage";
import {getAction} from "@/api/manage";
import moment from 'moment';
import {JeecgListMixin} from '@/mixins/JeecgListMixin';

export default {
  name: "StmChannelProductImport",
  mixins: [JeecgListMixin],
  data() {
    return {
      visible: false,
      confirmLoading: false,
      disableSubmit: false,
      approveStatus: 2,
      id: "",
      form: this.$form.createForm(this),
      validatorRules: {
        id: {rules: [{required: true, message: "请选择渠道!"}]},
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 8},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 13},
      },
      type: 1,
      url: {
        list: "/stm/stmChannelInfo/list",
        importExcelUrl: "stm/stmChannelInfo/importChannelProductExcel",
      },
      loading: false,
    };
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    show() {
      console.log(222)
      this.visible = true;

    },
    close() {
      this.form.resetFields();
      this.$emit("close");
      this.visible = false;
    },
    handleSubmit() {
      this.visible = false;
      this.$emit("ok");
    },
    handleCancel() {
      this.close();
    },
    handleWarehouseFlag(e) {
      this.model.channelFlag = e;
    },
    searchQuery() {

    },
    handleImport(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList);
      }
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          this.$emit("ok");
          if (info.file.response.code === 201) {
            let {message, result: {msg, fileUrl, fileName}} = info.file.response
            let href = window._CONFIG['domianURL'] + fileUrl
            this.$warning({
              title: message,
              content: (
                <div>
                  <span>{msg}</span><br/>
                  <span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
                </div>
              )
            })
          } else {
            this.$message.success(info.file.response.message || `${info.file.name} 价格导入成功`);
          }
        } else {
          this.$message.error(`${info.file.name} ${info.file.response.message}.`);
        }
      } else if (info.file.status === 'error') {
        this.$message.error(`文件上传失败: ${info.file.msg} `);
      }
    },
  }
};
</script>

<style scoped>

</style>